import os


def count_lines(filepath):
    # print(filepath)
    nlines = 0
    with open(filepath, 'r', encoding='utf-8') as f:
        for line in f.readlines():
            if len(line.strip()) > 0:
                nlines += 1
            # nlines += 1
    return nlines


def count_all_lines(folder):
    nlines = 0
    for root, _, files in os.walk(folder):
        for name in files:
            if name.endswith('.h') or name.endswith('.cpp'):
                path = os.path.join(root, name)
                nlines += count_lines(path)
    return nlines


if __name__ == '__main__':
    root = '../src/engine'
    nlines = count_all_lines(root)
    print(nlines)
